<!DOCTYPE html> 
<html>
<head>  
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"> 
	<title>Oauth 授权</title> 
	<meta charset="utf-8" />
</head>
<body style="word-break:break-all;">
<?php
//授权完成


$APPID = 'wx7197628dc9966e3d';
$SECRET = '2df3acd8ec9b083b374fedf18fa723e5';
$CODE = '';
$TOKEN = '';
$OPENID = ''; 

//第一步：用户同意授权，获取code
$CODE = $_GET['code'];
// echo $CODE; 
//第二步：通过code换取网页授权access_token
$url1 = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$APPID.'&secret='.$SECRET.'&code='.$CODE.'&grant_type=authorization_code';
$result1 = file_get_contents($url1);
$result1 = json_decode($result1,true);
 

$TOKEN = $result1['access_token'];
$OPENID = $result1['openid'];

//print_r($result1);

//第三步：拉取用户信息(需scope为 snsapi_userinfo)

$url2 = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$TOKEN.'&openid='.$OPENID.'&lang=zh_CN';

$result2 = file_get_contents($url2);
$returnStr = $result2;
$result2 = json_decode($result2,true);
 
$callBackUrl = $_GET['url'].'?satus=1&data='.urlencode($returnStr);

//echo '点击【<a href="'.$callBackUrl.'">跳转到页面来源</a>】<br />'.$callBackUrl;
?>

<script language="javascript">
 location.href='<?php echo $callBackUrl; ?>';
</script>
</body>
</html>